package com.longteng.common.config.exception;


import com.longteng.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.awt.image.RescaleOp;

/**
 * @author shkstart
 * @Description
 * @create 2024--01--08--11:39
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //全局异常处理，执行方法
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail().message("未知错误");
    }

    //特定异常处理
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result ariErrot(Exception ex){
        ex.printStackTrace();
        return Result.fail().message("出现0");
    }

    //自定义异常类
    @ExceptionHandler(SysRoleException.class)
    @ResponseBody
    public Result sysRoleException(SysRoleException se){
        return Result.fail().code(se.getCode()).message(se.getMsg());
    }
}
